********************************************************************************
** 	TITLE:		us1988_anes_contact_networks                                  ** 	
**  AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       NES1988                                                       **
**  DATE:	    October 2022 						                          **	
**	VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "us1988_anes_contact_networks", replace

* Open the dataset

use "NES1988.dta", clear

* Generate variable for interview year

gen inty = 1988


**************************
** STATE-LEVEL OUTCOMES **
**************************

* Note: 1 = Republican, 2 = Democrat

gen statewinner = .

replace statewinner = 1 if V880010 == 1
replace statewinner = 1 if V880010 == 2
replace statewinner = 1 if V880010 == 4
replace statewinner = 1 if V880010 == 5
replace statewinner = 1 if V880010 == 6
replace statewinner = 1 if V880010 == 8
replace statewinner = 1 if V880010 == 9
replace statewinner = 1 if V880010 == 10
replace statewinner = 2 if V880010 == 11
replace statewinner = 1 if V880010 == 12
replace statewinner = 1 if V880010 == 13
replace statewinner = 2 if V880010 == 15
replace statewinner = 1 if V880010 == 16
replace statewinner = 1 if V880010 == 17
replace statewinner = 1 if V880010 == 18
replace statewinner = 2 if V880010 == 19
replace statewinner = 1 if V880010 == 20
replace statewinner = 1 if V880010 == 21
replace statewinner = 1 if V880010 == 22
replace statewinner = 1 if V880010 == 23
replace statewinner = 1 if V880010 == 24
replace statewinner = 2 if V880010 == 25
replace statewinner = 1 if V880010 == 26
replace statewinner = 2 if V880010 == 27
replace statewinner = 1 if V880010 == 28
replace statewinner = 1 if V880010 == 29
replace statewinner = 1 if V880010 == 30
replace statewinner = 1 if V880010 == 31
replace statewinner = 1 if V880010 == 32
replace statewinner = 1 if V880010 == 33
replace statewinner = 1 if V880010 == 34
replace statewinner = 1 if V880010 == 35
replace statewinner = 2 if V880010 == 36
replace statewinner = 1 if V880010 == 37
replace statewinner = 1 if V880010 == 38
replace statewinner = 1 if V880010 == 39
replace statewinner = 1 if V880010 == 40
replace statewinner = 2 if V880010 == 41
replace statewinner = 1 if V880010 == 42
replace statewinner = 2 if V880010 == 44
replace statewinner = 1 if V880010 == 45
replace statewinner = 1 if V880010 == 46
replace statewinner = 1 if V880010 == 47
replace statewinner = 1 if V880010 == 48
replace statewinner = 1 if V880010 == 49
replace statewinner = 1 if V880010 == 50
replace statewinner = 1 if V880010 == 51
replace statewinner = 2 if V880010 == 53
replace statewinner = 2 if V880010 == 54
replace statewinner = 2 if V880010 == 55
replace statewinner = 1 if V880010 == 56


*********************
** COMPETITIVENESS **
*********************

* Margin of victory by state (absolute difference between Democratic and Republican candidates)

gen margin = .

replace margin = 19.30175 if V880010 == 1
replace margin = 23.31998 if V880010 == 2
replace margin = 21.20639 if V880010 == 4
replace margin = 14.17611 if V880010 == 5
replace margin = 3.567123 if V880010 == 6
replace margin = 7.776482 if V880010 == 8
replace margin = 5.103043 if V880010 == 9
replace margin = 12.40221 if V880010 == 10
replace margin = 68.34252 if V880010 == 11
replace margin = 22.36434 if V880010 == 12
replace margin = 20.25444 if V880010 == 13
replace margin = 9.518394 if V880010 == 15
replace margin = 26.06781 if V880010 == 16
replace margin = 2.083714 if V880010 == 17
replace margin = 20.15659 if V880010 == 18
replace margin = 10.21545 if V880010 == 19
replace margin = 13.23335 if V880010 == 20
replace margin = 11.63789 if V880010 == 21
replace margin = 10.21016 if V880010 == 22
replace margin = 11.45189 if V880010 == 23
replace margin = 2.90855 if V880010 == 24
replace margin = 7.853992 if V880010 == 25
replace margin = 7.895618 if V880010 == 26
replace margin = 7.017109 if V880010 == 27
replace margin = 20.82269 if V880010 == 28
replace margin = 3.981125 if V880010 == 29
replace margin = 5.87299 if V880010 == 30
replace margin = 20.97178 if V880010 == 31
replace margin = 21.36256 if V880010 == 32
replace margin = 26.15637 if V880010 == 33
replace margin = 13.64197 if V880010 == 34
replace margin = 4.956779 if V880010 == 35
replace margin = 6.430672 if V880010 == 36
replace margin = 16.26199 if V880010 == 37
replace margin = 13.05923 if V880010 == 38
replace margin = 10.85492 if V880010 == 39
replace margin = 16.64714 if V880010 == 40
replace margin = 4.666744 if V880010 == 41
replace margin = 2.317837 if V880010 == 42
replace margin = 11.70525 if V880010 == 44
replace margin = 23.92361 if V880010 == 45
replace margin = 6.343632 if V880010 == 46
replace margin = 16.34463 if V880010 == 47
replace margin = 12.60419 if V880010 == 48
replace margin = 34.17253 if V880010 == 49
replace margin = 3.516239 if V880010 == 50
replace margin = 20.5038 if V880010 == 51
replace margin = 1.591259 if V880010 == 53
replace margin = 4.73756 if V880010 == 54
replace margin = 3.618122 if V880010 == 55
replace margin = 22.51701 if V880010 == 56


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

gen surveydate = mdy(V880043,V880044,inty)

format %tdMon_DD,_CCYY surveydate

gen edate = 19881108

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = electiondate - surveydate

* Gender

gen male = V880413

recode male (2=0)

* Age

gen age = V880417

replace age = . if age < 18

* Education

gen education = V880422

recode education (98=.)
recode education (99=.)

* Interest for election

gen interest = V880097

recode interest (9=.)

replace interest = 6 - interest

replace interest = 2 if interest == 3
replace interest = 3 if interest == 5

* Caring about outcome (national)

gen care_whole = V880102

recode care_whole (8=.)
recode care_whole (9=.)

recode care_whole (3=0)

* Closeness of election (national)

gen closeness_whole = V880099

recode closeness_whole (0=.)
recode closeness_whole (8=.)
recode closeness_whole (9=.)

recode closeness_whole (1=0)
recode closeness_whole (3=1)

* Closeness of election (state)

gen closeness_state = V880101

recode closeness_state (0=.)
recode closeness_state (8=.)
recode closeness_state (9=.)

recode closeness_state (1=0)
recode closeness_state (3=1)

* Party identification scale (national)

gen pidscale = V880274

recode pidscale (7=.) // Other minor party (only one respondent) recoded as missing data
recode pidscale (8=3) // Apolitical recoded as Independent
recode pidscale (9=.) // NA recoded as missing data

replace pidscale = pidscale + 1

gen pidscale_whole = pidscale

label define pidscale 1 "Strong loser PID" 2 "Weak loser PID" 3 "Leaner loser PID" 4 "No PID" 5 "Leaner winner PID" 6 "Weak winner PID" 7 "Strong winner PID"
label values pidscale_whole pidscale

* Party identification scale (state)

gen pidscale_state = pidscale if statewinner == 1
replace pidscale_state = 8 - pidscale if statewinner == 2

label values pidscale_state pidscale

* TV news attentiveness

gen watchtv = V880128

gen tv = V880129

recode tv (0=.)
recode tv (8=.)
recode tv (9=.)

replace tv = 6 - tv

replace tv = 1 if watchtv == 5
replace tv = 1 if watchtv == 8

recode tv (.=-99)

* Press news attentiveness

gen readpress = V880130

gen press = V880135

recode press (0=.)
recode press (8=.)
recode press (9=.)

replace press = 6 - press

replace press = 1 if readpress == 5
replace press = 1 if readpress == 8
replace press = 1 if V880134 == 5

recode press (.=-99)

* Magazine news attentiveness

gen readmagazines = V880136

gen magazines = V880137

recode magazines (0=.)
recode magazines (8=.)
recode magazines (9=.)

replace magazines = 6 - magazines

replace magazines = 1 if readmagazines == 5
replace magazines = 1 if readmagazines == 8

recode magazines (.=-99)

* Radio news attentiveness

gen listenradio = V880138

gen radio = V880139

recode radio (0=.)
recode radio (8=.)
recode radio (9=.)

replace radio = 6 - radio // Note: 3-point scale (rather than 5-point scale)

recode radio (1=2)
recode radio (3=4)

replace radio = 1 if listenradio == 5
replace radio = 1 if listenradio == 8

recode radio (.=-99)

* News attentiveness index

egen news = rowmax(tv press magazines radio)

recode news (-99=.)

* Ted Kennedy - Correct answer (Massachusetts Senator) = 1, Incorrect answer = 0

gen kennedy = V880871

recode kennedy (0=.)
recode kennedy (9=.)

recode kennedy (5=0)
recode kennedy (8=0)

* George Shultz - Correct answer (United States Secretary of State) = 1, Incorrect answer = 0

gen shultz = V880872

recode shultz (0=.)
recode shultz (9=.)

recode shultz (5=0)
recode shultz (8=0)

* William Rehnquist - Correct answer (Supreme Court Chief Justice) = 1, Incorrect answer = 0

gen rehnquist = V880873

recode rehnquist (0=.)
recode rehnquist (9=.)

recode rehnquist (5=0)
recode rehnquist (8=0)

* Mikhail Gorbachev - Correct answer (USSR President) = 1, Incorrect answer = 0

gen gorbachev = V880874

recode gorbachev (0=.)
recode gorbachev (9=.)

recode gorbachev (5=0)
recode gorbachev (8=0)

* Margaret Thatcher - Correct answer (British Prime Minister) = 1, Incorrect answer = 0

gen thatcher = V880875

recode thatcher (0=.)
recode thatcher (9=.)

recode thatcher (5=0)
recode thatcher (8=0)

* Yasser Arafat - Correct answer (PLO leader) = 1, Incorrect answer = 0

gen arafat = V880876

recode arafat (0=.)
recode arafat (9=.)

recode arafat (5=0)
recode arafat (8=0)

* Jim Wright - Correct answer (House speaker) = 1, Incorrect answer = 0

gen wright = V880877

recode wright (0=.)
recode wright (9=.)

recode wright (5=0)
recode wright (8=0)

* Party with the most members in the U.S. House before election - Correct answer (Democrat) = 1, Incorrect answer = 0

gen house = V880878

recode house (0=.)
recode house (9=.)

recode house (1=0)
recode house (5=1)
recode house (8=0)

* Party with the most members in the U.S. Senate before election - Correct answer (Democrat) = 1, Incorrect answer = 0

gen senate = V880879

recode senate (0=.)
recode senate (9=.)

recode senate (1=0)
recode senate (5=1)
recode senate (8=0)

* Political knowledge index

gen knowledge = kennedy + shultz + rehnquist + gorbachev + thatcher + arafat + wright + house + senate

* Political discussion

gen discussion = V880127

recode discussion (8=.)
recode discussion (9=.)

gen discussion_3pts = 0 if discussion < 2 & discussion!=.
replace discussion_3pts = 1 if discussion >= 2 & discussion < 4 & discussion!=.
replace discussion_3pts = 2 if discussion >= 4 & discussion!=.


*********************************
** NATIONAL-LEVEL EXPECTATIONS **
*********************************

* Forecasts (1 = Republican, 2 = Democrat, 7 = other)

gen forecast_whole = V880098

recode forecast_whole (9=.)

* Identify correct forecasts

gen correct_whole_d = 0 if forecast_whole!=1 & forecast_whole!=.
replace correct_whole_d = 1 if forecast_whole == 1


******************************
** STATE-LEVEL EXPECTATIONS **
******************************

* Forecasts (1 = Republican, 2 = Democrat, 7 = other)

gen forecast_state = V880100

recode forecast_state (9=.)

* Identify correct forecasts

gen correct_state_d = 0 if forecast_state!=statewinner & forecast_state!=.
replace correct_state_d = 1 if forecast_state == statewinner & forecast_state!=.


**********
** SAVE **
**********

save "us1988_anes.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts (national)

logistic correct_whole_d discussion pidscale_whole interest news knowledge i.care_whole i.closeness_whole age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1

* Regression analysis and percentage of correct and incorrect forecasts (state)

melogit correct_state_d discussion pidscale_state interest news knowledge i.closeness_state age i.male education time margin || V880010: , or
estimates table, star(.05 .01 .001)

tab correct_state_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_whole_d "Presidency winner (DV)"
label variable correct_state_d "State winner (DV)"
label variable discussion "Discussion"
label variable pidscale_whole "National PID"
label variable pidscale_state "State PID"
label variable interest "Interest"
label variable news "News attentiveness"
label variable knowledge "Political knowledge"
label variable care_whole "Caring about outcome"
label variable closeness_whole "Perceived closeness"
label variable closeness_state "Perceived closeness"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"
label variable margin "Margin"

quietly logistic correct_whole_d discussion pidscale_whole interest news knowledge i.care_whole i.closeness_whole age i.male education time

estpost tabstat correct_whole_d discussion pidscale_whole interest news knowledge care_whole closeness_whole age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us1988_anes_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 1988 American presidential election (ANES), national level") replace

eststo clear

quietly melogit correct_state_d discussion pidscale_state interest news knowledge i.closeness_state age i.male education time margin || V880010: , or

estpost tabstat correct_state_d discussion pidscale_state interest news knowledge closeness_state age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us1988_anes_summary_state.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 1988 American presidential election (ANES), state level") replace

eststo clear

log close